from csr_utils import log

from commons.api_status_code import APIStatusCode


class ResultDao:
    # data, 200, {"ContentType": "application/json"}

    @classmethod
    def succee(cls,message = "Success",data=""):
        http_respone_data = cls._api_status_code_to_dict(APIStatusCode.SUCCESS)
        http_respone_data.setdefault("message",message)
        http_respone_data.setdefault("data",data)
        return (http_respone_data,200,{"ContentType": "application/json"})

    @classmethod
    def fail(cls, api_status_code:APIStatusCode):
        http_respone_data = cls._api_status_code_to_dict(api_status_code)
        log.warn(api_status_code.message)
        return (http_respone_data,500,{"ContentType": "application/json"})

    @classmethod
    def _api_status_code_to_dict(cls, api_status_code):
        return {"code":api_status_code.code,"message":api_status_code.message}


